package net.zjitc.service.Impl;

import net.zjitc.mapper.AdminMapper;
import net.zjitc.pojo.Admin;
import net.zjitc.service.AdminService;
import net.zjitc.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;
    @Override
    public Admin findAdmin(String username,String password){

       Admin admin = adminMapper.findAdmin(username);
        if(admin==null){
           return null;
        }
        //密码加密
        String hashedPassword = MD5Util.hashPasswordWithSalt(password, admin.getSalt());
        if(hashedPassword.equals(admin.getPassword())){
            return admin;
        }
        return null;
    }
}
